/**
 * 新闻快讯 Store 模块
 * 用于存储和管理新闻快讯数据
 */

export default {
  namespaced: true,
  state: {
    // 当前选中的新闻详情
    currentNews: {
      id: '',
      title: '',
      content: '',
      time: '',
      timestamp: 0
    }
  },
  getters: {
    currentNews: state => state.currentNews,
  },
  mutations: {
    /**
     * 设置当前新闻详情
     * @param {Object} state - Vuex state
     * @param {Object} newsData - 新闻数据对象
     */
    SET_CURRENT_NEWS(state, newsData) {
      state.currentNews = {
        id: newsData.id || '',
        title: newsData.title || '',
        content: newsData.content || '',
        time: newsData.time || '',
        timestamp: newsData.timestamp || 0
      }
    },
    /**
     * 清空当前新闻详情
     * @param {Object} state - Vuex state
     */
    CLEAR_CURRENT_NEWS(state) {
      state.currentNews = {
        id: '',
        title: '',
        content: '',
        time: '',
        timestamp: 0
      }
    }
  },
  actions: {
    /**
     * 设置当前新闻
     * @param {Object} context - Vuex context
     * @param {Object} newsData - 新闻数据
     */
    setCurrentNews({ commit }, newsData) {
      commit('SET_CURRENT_NEWS', newsData)
    },
    /**
     * 清空当前新闻
     * @param {Object} context - Vuex context
     */
    clearCurrentNews({ commit }) {
      commit('CLEAR_CURRENT_NEWS')
    }
  }
}

